package com.maple.annotation.metaannotation;


import android.annotation.TargetApi;
import android.os.Build;

import java.lang.reflect.Method;
import java.util.List;

import cn.com.vipkid.annotationtest.DocumentedAnnotation;
import cn.com.vipkid.annotationtest.InheritAnnotation;
import cn.com.vipkid.annotationtest.RepeatableAnnotation;
import cn.com.vipkid.annotationtest.RepeatableAnnotations;
import cn.com.vipkid.annotationtest.SourceAnnotation;
import cn.com.vipkid.annotationtest.TestAnnotation;

/**
 * Created by billy on 2019-05-22.
 * Copyright © 2017年 vipkid. All rights reserved.
 */
@TestAnnotation// ElementType.TYPE
@InheritAnnotation(1)
public class SampleClass</** @TestAnnotation */ T> {// ElementType.TYPE_PARAMETER

    @TestAnnotation// ElementType.CONSTRUCTOR
    public SampleClass(){}

    @TestAnnotation// ElementType.FIELD
    String text;

    @TestAnnotation// ElementType.METHOD
    @SourceAnnotation
    @DocumentedAnnotation(name = "func",desc = "啦啦啦啦啦")
    @InheritAnnotation
    public void func(@TestAnnotation List<T> text){// ElementType.PARAMETER
        @TestAnnotation// ElementType.LOCAL_VARIABLE
        int i = 0;
    }
    @InheritAnnotation
    public void func2(){

    }

    @RepeatableAnnotation(name = "a")
    @RepeatableAnnotation(name = "b")
    @RepeatableAnnotation(name = "c")
    public static class InheritedTest1Class extends SampleClass{

        @Override
        public void func(List text) {
            super.func(text);
        }

    }

    @TargetApi(Build.VERSION_CODES.N)
    public static void main(String[] args) throws NoSuchMethodException, SecurityException, NoSuchFieldException {
        Class<InheritedTest1Class> clazz = InheritedTest1Class.class;
//        //对类进行测试
//        System.out.println("对类进行测试");
//        if(clazz.isAnnotationPresent(InheritAnnotation.class)){
//            System.out.println(clazz.getAnnotation(InheritAnnotation.class).value());
//        }
//        System.out.println();
//        //对方法 进行测试
//        System.out.println("对方法1进行测试");
//        Method method = clazz.getMethod("func", List.class);
//        if(method.isAnnotationPresent(InheritAnnotation.class)){
//            System.out.println(method.getAnnotation(InheritAnnotation.class).value());
//        }
//        System.out.println();
//        //对方法2 进行测试
//        System.out.println("对方法2进行测试");
//        Method method2 = clazz.getMethod("func2");
//        if(method2.isAnnotationPresent(InheritAnnotation.class)){
//            System.out.println(method2.getAnnotation(InheritAnnotation.class).toString());
//        }

        System.out.println();
        //对repeatable 进行测试
        System.out.println("对repeatable 进行测试");
        if(clazz.isAnnotationPresent(RepeatableAnnotations.class)){
            RepeatableAnnotations repeatableAnnotations = clazz.getAnnotation(RepeatableAnnotations.class);
            for (int i = 0; i < repeatableAnnotations.value().length; i++) {
                System.out.println(repeatableAnnotations.value()[i].name());
            }
        }
    }


}
